import request from '@/config/axios'

export interface TenantVO {
  id?: number
  name?: string
  contactName?: string
  contactMobile?: string
  status?: number
  website?: string
  packageId?: number
  username?: string
  expireTime?: Date
  accountCount?: number
  createTime?: Date
  businessModel?: number
  tenantType?: number //租户类型
  tenantIndate?: string //有效期
  tenantIndateUnit?: number //有效期单位
  logo?: string //租户logo
  tenantCount?: number //租户数量
  businessLicense?: string //租户营业执照
  shortName?: string //简称
  acreage?: string //面积
  introduction?: string
  phone?: string
  areaId?: number
  detailAddress?: string
  openingTime?: string
  closingTime?: string
  latitude?: number
  longitude?: number
  makeOpeningTime?: string
  makeClosingTime?: string
  tenantTypeName?: string
  affiliatePackageId?: EmptyArrayType
  packageIdsList?: EmptyArrayType
  enableAcceptUser: boolean
  enableShareUser: boolean
  shareTenants: EmptyArrayType
  postIds?: EmptyArrayType //授权岗位
  openType?: EmptyArrayType //同步开通
  wxAppid?: string //微信小程序APPID
}

export interface TenantPageReqVO extends PageParam {
  name?: string
  contactName?: string
  contactMobile?: string
  status?: number
  createTime?: Date[]
  tenantType?: number //租户类型
}

export interface TenantExportReqVO {
  name?: string
  contactName?: string
  contactMobile?: string
  status?: number
  createTime?: Date[]
}
export interface TenantUpdatePasswordVO {
  id: string
  contactMobile: string
}
export interface ListTenantTypeVO {
  flag: number
  type: string
}
export interface ChildTenantWithPostListVO extends TenantVO {
  posts: any[]
  roles: any[]
}

// 查询租户列表
export const getTenantPage = (params: TenantPageReqVO) => {
  return request.get({ url: '/system/tenant/page', params })
}
// 查询租户当前租户可选租户类型
export const getTenantTypeListByType = () => {
  return request.get({ url: '/system/tenant/getTenantTypeListByType' })
}

// 获取当前租户创建的租户列表(带岗位列表)
export const getChildTenantWithPostList = async (
  params?: any
): Promise<ChildTenantWithPostListVO[]> => {
  return await request.get({ url: '/system/tenant/getChildTenantWithPostList', params })
}

// 查询租户详情
export const getTenant = (id: number) => {
  return request.get({ url: '/system/tenant/get?id=' + id })
}
// 根据租户类型查询级联租户类型
export const getListTenantType = (params: ListTenantTypeVO) => {
  return request.get({ url: '/system/tenant/list-tenant-type', params })
}

// 新增租户
export const createTenant = (data: TenantVO) => {
  return request.post({ url: '/system/tenant/create', data })
}

// 修改租户
export const updateTenant = (data: TenantVO) => {
  return request.put({ url: '/system/tenant/update', data })
}

// 删除租户
export const deleteTenant = (id: number) => {
  return request.delete({ url: '/system/tenant/delete?id=' + id })
}
// 租户关联租户
export const relationTenant = (data: TenantVO) => {
  return request.put({ url: '/system/tenant/relationTenant', data })
}

// 导出租户
export const exportTenant = (params: TenantExportReqVO) => {
  return request.download({ url: '/system/tenant/export-excel', params })
}
// 重置租户管理员密码
export const updatePasswordTenant = (data: TenantUpdatePasswordVO) => {
  return request.put({ url: '/system/tenant/user/update-password', data })
}
// 获取当前租户(带岗位列表)
export const getCurrentTenantWithPost = async () => {
  return await request.get({ url: '/system/tenant/getCurrentTenantWithPost' })
}
